<template>
    <div class="mod-order" style="margin: 10px">
        <!--查询面板-->
        <SearchPanel ref="searchPanel" :search-config="searchConfig" @startSearch="startSearch">
            <!-- <el-form-item>
                <el-button icon="el-icon-plus" type="primary" size="mini" @click="add">新增</el-button>
            </el-form-item> -->

            <!-- <el-form-item>
                <el-button type="danger" size="mini" @click="batchDel" :disabled="selectDataList.length == 0">批量删除</el-button>
            </el-form-item> -->
        </SearchPanel>

        <!-- 查询结果 -->
        <ResultListPanel
            tableRef="table"
            ref="multipleTable"
            :checkBoxEnable="true"
            :data="dataList ? dataList : []"
            :listConfig="resultColConfig"
            :listLoading="listLoading"
            @actionClick="actionClick"
            @paginationChange="paginationChange"
            :tagTextExchange="tagTextExchange"
            @selectionChange="selectionChange"
        ></ResultListPanel>
    </div>
</template>

<script>
import {
    INDEX_SEARCH_CONFIG,
    JD_SHGL_INDEX_SEARCH_RESULT_ITEMS,
    NZ_SHGL_INDEX_SEARCH_RESULT_ITEMS,
    ZJF_SHGUL_INDEX_SEARCH_RESULT_ITEMS
} from './config';

import { isPostpone, isType } from '../../utils/util';
import ResultListPanel from '../../components/ResultListPanel';
import SearchPanel from '../../components/SearchPanel';
import API from '@/api';
import cloneDeep from 'lodash/cloneDeep';

import { identityStatusType, userType , commercialUserType } from '../../utils/util';

export default {
    components: {
        ResultListPanel,
        SearchPanel
    },
    data() {
        return {
            visible: false,
            selectDataList: [],

            // 搜索项配置
            searchConfig: INDEX_SEARCH_CONFIG,
            resultColConfig: [],
            listLoading: false, // 数据列表显示状态
            dataList: [], //  数据列表

            /* 分页查询数据 */
            pageSize: 10,
            pageNum: 1,
            totalPage: 0,

            /* 查询条件参数 */
            dataForm: {
                name: null
            },
            type: 1
        };
    },

    mounted() {
        this.getList();
    },

    watch: {
        //- 解决 同一页面，数据不刷新问题

        // 监听相同路由下参数变化的时候，从而实现异步刷新
        $route(to, from) {
            this.getList();
            this.nickname = this.$route.query.nickname; //修改页面标题
        }
    },

    methods: {
        selectionChange(val) {
            this.selectDataList = val;
        },

        /***
         * 搜索面板触发 搜索事件
         * @param params
         */
        startSearch(params) {
            this.dataForm = params;
            this.pageNum = 1;
            this.$set(this.$refs.multipleTable['pageParams'], 'pageNum', 1);

            this.getList();
        },

        //新增按钮  执行逻辑
        add() {},

        /***
         * 触发 列表 操作按钮 （ 编辑 和 删除 ）
         * @param data
         * @param item
         */
        actionClick([data, item]) {
            if (item.alias === 'show') {

                var listId = data.userId;            
                this.$router.push({ path: '/realNameCertification/showDetails', query: { itemData: data, type: 2} });
            }
        },

        tagTextExchange([data, item]) {
            //实名认证状态
            if (item.alias == 'identityStatus') {
                return identityStatusType(data.identityStatus);
            }

            //用户类型
            if (item.alias == 'userType') {
                return userType(data.userType);
            }

            //商户类型
            if(item.alias=='merchantType'){
                return commercialUserType(data.merchantType);
            }
        },

        /**
         * 分页器发生改变 触发事件
         * @param page
         */
        paginationChange(page) {
            this.pageSize = page.pageSize;
            this.pageNum = page.pageNo;
            this.getList();
        },

        // 列表 接口
        getList() {
            //处理列表 显示
            switch (this.$route.path) {
                case '/realNameCertification/jdshgl/index':
                    //基地商户管理 - 实名认证查看

                    this.resultColConfig = JD_SHGL_INDEX_SEARCH_RESULT_ITEMS;

                    break;

                case '/realNameCertification/nzshgl/index':
                    //农资商户管理 - 实名认证查看

                    this.resultColConfig = NZ_SHGL_INDEX_SEARCH_RESULT_ITEMS;

                    break;

                case '/realNameCertification/zjfshgl/index':
                    //资金方商户管理 - 实名认证查看

                    this.resultColConfig = ZJF_SHGUL_INDEX_SEARCH_RESULT_ITEMS;

                    break;
            }

            //公用传递信息
            let params = cloneDeep(this.dataForm);
            params.pageNum = this.pageNum;
            params.pageSize = this.pageSize;

            this.listLoading = true;
            var tick;
            switch (this.$route.path) {
                case '/realNameCertification/jdshgl/index':
                    //基地商户管理 - 实名认证查看

                    //基地商户专用查询参数
                    let queryParams = {};

                    //查询参数
                    let postParams = {};
                    postParams.pageNum = this.pageNum;
                    postParams.pageSize = this.pageSize;

                    if (params.name != null) {
                        queryParams.userId = params.name;
                        postParams.query = queryParams;
                    }

                    tick = API.realNameCertification.getJD_SMRZ_List(postParams);
                    break;

                case '/realNameCertification/nzshgl/index':
                    //农资商户管理 - 实名认证查看

                    tick = API.realNameCertification.getNZ_SMRZ_List(params);

                    break;

                case '/realNameCertification/zjfshgl/index':
                    //资金方商户管理 - 实名认证查看

                    tick = API.realNameCertification.getZJF_SMRZ_List(params);

                    break;
            }

            tick.then((res) => {
                console.log(res);
                this.listLoading = false;
                this.totalPage = res.result.total;
                this.dataList = res.result.rows;
                this.$set(this.$refs.multipleTable['pageParams'], 'total', res.result.total);
            });
        }
    }
};
</script>

<style>
</style>